package ua.cs.stu.ics.dao.dbf;

import ua.cs.stu.ics.dao.IStudentDAO;
import ua.cs.stu.ics.dbf.domain.StudentDomain;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * author: evgeniy
 */
public class StudentDAO implements IStudentDAO{
    private List<StudentDomain> list = new ArrayList<StudentDomain>();
    private List<String> fio = new ArrayList<String>();
    
    public void add(StudentDomain domain) {
        list.add(domain);
    }

    public List <StudentDomain>findAll() {
        return list;
    }
    
    public List<String> findFIOs() {
    	List<StudentDomain> as = findAll();
        for (StudentDomain sd: as){
             fio.add(sd.getFio());
        }
        Collections.sort(fio);
        return fio;
    }
    
    public StudentDomain findStudent(String name) {
    	StudentDomain st= new StudentDomain();
    	ArrayList<StudentDomain> as = (ArrayList<StudentDomain>) findAll();
        for (StudentDomain sd: as){
            if (sd.getFio().equals(name)){
            	st=sd;
            }
        }
       return st;
    }
}

